package com.bolingcavalry.crm.servicedetails.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.base.PageResult;
import com.base.ResponseResult;
import com.bolingcavalry.crm.servicedetails.service.ServiceDetailsService;
import com.entity.servicedetails.ServiceDetails;
import com.entity.servicedetails.ServiceDetailsDto;
import com.entity.servicedetails.ServiceDetailsVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "售后明细管理")
@RestController
@RequestMapping("/servicedetails")
public class ServiceDetailsController {
    @Autowired
    private ServiceDetailsService serviceDetailsService;
    @PostMapping("/add")
    public ResponseResult add(@RequestBody ServiceDetails serviceDetails) {
        return serviceDetailsService.insert(serviceDetails);
    }

    /**
     * 批量添加服务明细
     * @param serviceDetailsDtos
     * @return
     */
    @PostMapping("/addlist")
    public ResponseResult addlist(@RequestBody ServiceDetailsDto[] serviceDetailsDtos) {
        return serviceDetailsService.insertlist(serviceDetailsDtos);
    }
    @GetMapping("/list")
    public ResponseResult<ServiceDetailsVo> list(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "serviceOrderNumber", required = false) String serviceOrderNumber, // 售后单号
            @RequestParam(value = "companyName", required = false) String companyName, // 售后单位（客户名）
            @RequestParam(value = "servicePersonnel", required = false) String servicePersonnel // 服务人员
    ) {
        IPage<ServiceDetailsVo> page = serviceDetailsService.getByConditions(pageNum, pageSize, serviceOrderNumber, companyName, servicePersonnel);
        PageResult<ServiceDetailsVo> result = new PageResult<>();
        result.setTotal(page.getTotal());
        result.setPages((int) page.getPages());
        result.setCurrent((int) page.getCurrent());
        result.setSize((int) page.getSize());
        result.setRecords(page.getRecords());
        return ResponseResult.success("查询成功", result);
    }

    @GetMapping("/getall")
    public ResponseResult<ServiceDetails> getall() {
        List<ServiceDetails> list = serviceDetailsService.list();
        return ResponseResult.success("查询成功", list);
    }

//    @DeleteMapping("/delete")
//    public ResponseResult delete(@RequestBody String[] ids) {
//        return serviceDetailsService.batchDelete(ids);
//    }
}
